import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
import { Role } from "./role.entity";
import { Blog } from "../../blog/entities/blog.entity";
import { Daily } from "../../daily/entities/daily.entity";
import { Star } from "../../star/entities/star.entity";
import { Like } from "../../like/entities/like.entity";

@Entity({
  name: 'users'
})
export class User {
  @PrimaryGeneratedColumn()
    id: number;

    @Column({
        length: 50,
        comment: '用户名'
    })
    username: string;

    @Column({
        length: 50,
        comment: '密码'
    })
    password: string;

    @Column({
        name: 'nick_name',
        length: 50,
        comment: '昵称'
    })
    nickName: string;


    @Column({
        comment: '邮箱',
        length: 50
    })
    email: string;


    @Column({
        comment: '头像',
        length: 100,
        nullable: true
    })
    headPic: string;

    @Column({
        comment: '手机号',
        length: 20,
        nullable: true
    })
    phoneNumber: string;

    @Column({
        comment: '是否冻结',
        default: 0
    })
    isFrozen: 0|1;

    @Column({
        comment: '是否是管理员',
        default: false
    })
    isAdmin: boolean;

    @CreateDateColumn()
    createTime: Date;

    @UpdateDateColumn()
    updateTime: Date;

    @ManyToMany(()=>Role)
    @JoinTable({
      name: 'user-roles'
    })
    roles: Role[]

    // 一个用户有多篇文章
    @OneToMany(() => Blog, blog => blog.user)
    blogs: Blog[] 

    @OneToMany(() => Daily, daily => daily.user)
    dailys: Daily[]

    @OneToMany(() =>Star, star => star.user)
    stars: Star[]

    @OneToMany(() =>Like, like=>like.user)
    likes: Like[]
}